﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using ZLDC.Common.Estate;


namespace ZLDC.DAL.Estate
{
    public class ShowFloorPaperDAL
    {
        public static void p_showFloorPaper_save(int Id, string paperNo, int addUserId, int oprUserId, string oprUserName, int ownerUserId, string ownerUserName, int isUse, out string outmsg, out int newid, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@Id", Id));
            parms.Add(new SqlParameter("@paperNo", paperNo));
            parms.Add(new SqlParameter("@addUserId", addUserId));
            parms.Add(new SqlParameter("@oprUserId", oprUserId));
            parms.Add(new SqlParameter("@oprUserName", oprUserName));
            parms.Add(new SqlParameter("@ownerUserId", ownerUserId));
            parms.Add(new SqlParameter("@ownerUserName", ownerUserName));
            parms.Add(new SqlParameter("@isUse", isUse));

            SqlParameter pOutmsg = new SqlParameter("@outmsg", SqlDbType.VarChar, 256);
            pOutmsg.Direction = ParameterDirection.Output;
            parms.Add(pOutmsg);

            SqlParameter pNewid = new SqlParameter("@newid", SqlDbType.Int, 4);
            pNewid.Direction = ParameterDirection.Output;
            parms.Add(pNewid);
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);


            db.execute_procedure("p_showFloorPaper_save", parms);

            outmsg = (pOutmsg.Value == System.DBNull.Value) ? "" : Convert.ToString(pOutmsg.Value);
            newid = (pNewid.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pNewid.Value);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

        }
                                                public static int IsExistsPaperNo(int paperNo)
        {
            int rows = 0;
            using (_Database db = new _Database("estate"))
            {
                string sql = " select 1 from t_showFloorPaper where paperNo='" + paperNo + "' ";
                DataSet ds = db.Query(sql);
                if (ds.Tables[0].Rows.Count > 0)
                    rows = _Convert.ToInt(ds.Tables[0].Rows[0][0].ToString(), 0);

                db.close();
            }

            return rows;
        }

                                                                                public static DataTable p_showFloorPaper_list_table(int page, int pagesize, string condition, ref int total, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@page", page));
            parms.Add(new SqlParameter("@pagesize", pagesize));
            parms.Add(new SqlParameter("@condition", condition));

            SqlParameter pTotal = new SqlParameter("@total", SqlDbType.Int, 4);
            pTotal.Direction = ParameterDirection.InputOutput;
            pTotal.Value = total;
            parms.Add(pTotal);
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);

            DataTable dt = null;
            dt = db.GetDataTable("p_showFloorPaper_list", parms);

            total = (pTotal.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pTotal.Value);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

            return dt;
        }
                                                        public static void p_showFloorPaper_delete(string IdList, out string outmsg, _Database db)
        {
            outmsg = "";
            try
            {
                string sql = "delete from t_showFloorPaper where Id in(" + IdList + ") and isUse=0";
                if (db.ExecuteSql(sql) > 0)
                    outmsg = "回收成功！";
                else
                    outmsg = "回收失败,看楼纸已使用！";
            }
            catch (Exception ex)
            {
            }
            finally { db.close(); }
            
        }


    }
}
